package project.services_impl;

import java.util.List;

import javafx.scene.control.ListView;

import javax.transaction.Transactional;

import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.AttributeAccessor;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import project.services.InventoryService;
import project.dao.RoomDAO;
import project.dao.RoomDAOImpl;
import project.model.Pricing;
import project.model.PricingModel;
import project.model.Room;
import project.model.RoomCategory;

@Service(value="inventoryServiceImpl")
@Configurable
@Transactional
//add @Transactional annotation to where you operate the database, otherwise it may report error like
//"Write operations are not allowed in read-only mode"
public class InventoryServiceImpl implements InventoryService {
	
	@Autowired
	private HibernateTemplate hibernateTemplate;
	@Autowired
	private RoomDAOImpl roomDaoImpl;
	
	/*
	 * a few operational methods remain to be completed
	 * */
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	
	@Override
	public void addRoomCategory(RoomCategory category) {
		hibernateTemplate.save(category);
	}

	@Override
	public RoomCategory getRoomCategory(int categoryId) {
		//before using the code below you should first learn HQL
		//hibernateTemplate.find(queryString, values)
		return null;
	}

	@Override
	public void addRoom(Room room) {
		hibernateTemplate.save(room);
	}

	@Override
	public Room getRoomById(int roomId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Room> getRoomByName(String name) {
		List<Room> rooms = roomDaoImpl.findByName(name);
		return rooms;
	}
	
	@Override
	public List<Room> getAllRoomWithCategory(RoomCategory category) {
		return null;
	}

	@Override
	public void save() {
		//create default data
//		RoomCategory category = new RoomCategory();
//		category.setName("Double Rooms");
//		category.setDescription("Rooms with double bed");
//		Pricing pricing = new Pricing();
//		pricing.setId(1001);
//		pricing.setPriceGuest1(10.0);
//		category.setPricing(pricing);
//		this.addRoomCategory(category);
		
//		Room room = new Room();
//		room.setName("Room 101");
//		room.setDescription("Nice, spacious double bed room with usual amenities");
//		room.setRoomcategory(category);
//		this.addRoom(room);
	}


}
